<template>
  <el-dialog title="批量退回" :close-on-click-modal="false" :visible.sync="visible" ref="myDialog"
    class="JNPF-dialog JNPF-dialog_center" lock-scroll width="60%" :modal-append-to-body="false" append-to-body>
    <el-form :model="form" ref="formData" label-position="top" label-width="80px">
        
        <el-form-item label="" v-for="(item,index) in tableData" :key="index">
          <div><el-tag>{{ index+1 }}</el-tag> <span style="margin-left:10px"><strong>企业名称：</strong>{{ item.name_ch }}</span> <span style="margin-left:20px"><strong>申报类别：</strong>{{ item.name }}</span></div>
          <div>材料审核描述：</div>
          <el-input type="textarea" :autosize="{ minRows: 3}" v-model="item.value"></el-input>
          <el-divider></el-divider>
        </el-form-item>
        
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="handleBtnClose">取消</el-button>
        <el-button type="primary" @click="handleSubmit">提交</el-button>
      </div>
  </el-dialog>
</template>

<script>
import request from '@/utils/request'
import { deepClone } from '@/utils'
export default {
  data() {
    return {
      visible: false,
      modelId:'',
      ids:[],
      sendFunc:()=>{},
      form: {
        desc: '',
      },
      tableData: [],
      updateAuditId: '',
    };
  },
  methods: {
    init(modelId,data) {
      console.log('初始化数据',data)
      this.form.desc = ''
      let {ids,sendFunc,updateStatusApiId,updateAuditId} = data
      debugger
      if(!modelId){
        this.$message({
          type: 'error',
          message: '参数传入错误，请与系统管理员联系！',
          duration: 1500,
        })
        return
      }
      if (!sendFunc||typeof sendFunc != 'function') {
        this.$message({
          type: 'error',
          message: '参数传入错误2，请与系统管理员联系！',
          duration: 1500,
        })
        return
      }
      this.sendFunc = sendFunc
      this.modelId = modelId
      this.updateAuditId = updateAuditId
      this.ids = ids
      this.visible = true

      let apiUrl = '/api/system/DataInterface/'+updateStatusApiId+'/Actions/Call'
      let params = {
          "tenant_id": "",
          "paramList": [
              {
                  "field": "ids", "value": this.ids.join(',')
              },
          ]
      }
      request(
      {
        url: apiUrl,
        method: 'post',
        data:params
      }).then(tableRes => {
        this.tableData = tableRes.data.data
      }).catch(res2=>{
      })

    },
    handleBtnClose(){
        // 重置表单数据
        this.$refs.formData.resetFields();
        this.visible = false;
        this.$emit('refreshDataList', true)
    },
    handleClose() {
      // 重置表单数据
      this.$refs.formData.resetFields();
      this.visible = false;
      this.$emit('refreshDataList', true)
    },
    handleSubmit() {
      // 在这里执行提交逻辑，可以调用远程接口等
      // this.$message.info(''+this.ids)
      // console.log('Form Submitted:', this.form);
      debugger
          let params = this.tableData.map(v=>{
            return {
              id: v.id,
              audit_describe: v.value,
            }
          })
          console.log('穿惨', params);
          this.sendFunc(params,res1=>{
            this.handleClose();
          })
        
    },
  }
};
</script>
<style lang="scss" scoped>

</style>